package com.jie.jie.mvp.adpter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jie.jie.R;
import com.jie.jie.mvp.model.MeiziBean;
import com.jie.jie.mvp.ui.Mei2Activity;
import com.jie.jie.mvp.ui.Meimei;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by jie on 2017/1/23.
 */

public class MeiRvAdapter extends RecyclerView.Adapter<MeiRvAdapter.ViewHolder> {
    private Context context;
    private List<MeiziBean> datas;

    public MeiRvAdapter(Context context, List<MeiziBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.mvp_item3, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        Glide.with(context).load(datas.get(position).url).into(holder.mvpIv);
        holder.meitv.setText(datas.get(position).title);
        holder.mvpIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Meimei meimei = (Meimei) context;
                Intent intent = new Intent(meimei, Mei2Activity.class);
                intent.putExtra("page", datas.get(position).page);
                ((Meimei) context).startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.mvp_iv1)
        ImageView mvpIv;
        @Bind(R.id.mei_tv)
        TextView meitv;


        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
